package com.ybc.chinese.activity;

import android.app.ProgressDialog;
import android.support.v4.app.FragmentActivity;

import com.umeng.analytics.MobclickAgent;
import com.ybc.chinese.R;
import com.ybc.chinese.utils.DialogUtil;

/**
 * <p><p/>
 * Created by Yubch on 17/2/15.
 */
public class BaseActivity extends FragmentActivity {
    //用于友盟统计，是否含有fragment
    private boolean hasFragment = false;
    private ProgressDialog mRunningDialog;

    public void setHasFragment(boolean hasFragment) {
        this.hasFragment = hasFragment;
    }

    @Override
    protected void onResume() {
        super.onResume();
        // 友盟
        if (!hasFragment) {
            MobclickAgent.onPageStart(getClass().getSimpleName());
        }
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        // 友盟
        if (!hasFragment) {
            MobclickAgent.onPageEnd(getClass().getSimpleName());
        }
        MobclickAgent.onPause(this);
    }

    protected void showRunningDialog() {
        if (mRunningDialog == null) {
            mRunningDialog = DialogUtil.getProgressDialog(this, R.string.running);
        }
        if (!mRunningDialog.isShowing()) {
            mRunningDialog.show();
        }

    }

    protected void showRunningDialog(int resId) {
        if (mRunningDialog == null) {
            mRunningDialog = DialogUtil.getProgressDialog(this, resId);
        }
        if (!mRunningDialog.isShowing()) {
            mRunningDialog.show();
        }

    }

    protected void dismissRunningDialog() {
        if (mRunningDialog != null && mRunningDialog.isShowing()) {
            mRunningDialog.dismiss();
        }
    }
}
